import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';

import { ApiService } from '../shared/api.service';
import {SafeHtml} from "@angular/platform-browser";

@Component({
  selector: 'app-admin',
  template: `<div class="alert alert-danger">
    This is the <strong>⚙ ADMIN</strong> component.
    It will not redirect you to the login server.
    这是<strong> ADMIN</strong>组件。
    它不会将您重定向到登录服务器。
    <div [innerHTML]="pageContent"></div>
    <br/>
    - {{ apiResponse | async }}
  </div> `,
})
export class Admin1Component implements OnInit {
  apiResponse!: Observable<string>;
  pageContent: /*SafeHtml*/ string | undefined;

  constructor(private apiService: ApiService) { }

  ngOnInit() {
    this.apiService.getApiMessage();
    this.apiResponse = this.apiService.getProtectedApiResponse();
    this.apiService.loadPage('http://127.0.0.1:8080/messages/admin').subscribe(htmlContent=>{
      console.log("ddd======="+htmlContent);
      this.pageContent = htmlContent;
    })
  }
}
